<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb5">
      <el-col :span="1.5">
        <el-button
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:buzMember:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:buzMember:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:buzMember:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:buzMember:export']"
        >导出</el-button>
      </el-col>
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" class="el-form-search">
                        <el-form-item label="手机号码" prop="phone" class="el-form-search-item">
                            <el-input
                                    v-model="queryParams.phone"
                                    placeholder="请输入手机号码"
                                    clearable
                                    size="mini"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        
                        
                        
                        <el-form-item label="首选科目" prop="sxkm" class="el-form-search-item">
                            <el-input
                                    v-model="queryParams.sxkm"
                                    placeholder="请输入首选科目"
                                    clearable
                                    size="mini"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="再选科目" prop="zxkm" class="el-form-search-item">
                            <el-input
                                    v-model="queryParams.zxkm"
                                    placeholder="请输入再选科目"
                                    clearable
                                    size="mini"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="是否少数民族" prop="sfssmz" class="el-form-search-item">
                            <el-input
                                    v-model="queryParams.sfssmz"
                                    placeholder="请输入是否少数民族(0:否;1:是)"
                                    clearable
                                    size="mini"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="是否国家专项计划" prop="sfgjzxdfzx" class="el-form-search-item">
                            <el-input
                                    v-model="queryParams.sfgjzxdfzx"
                                    placeholder="请输入是否国家专项计划"
                                    clearable
                                    size="mini"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
						<el-form-item label="是否地方专项计划" prop="sfdfzx" class="el-form-search-item">
						    <el-input
						            v-model="queryParams.sfdfzx"
						            placeholder="请输入是否地方专项计划"
						            clearable
						            size="mini"
						            @keyup.enter.native="handleQuery"
						    />
						</el-form-item>
                        <el-form-item label="是否vip" prop="sfvip" class="el-form-search-item">
                            <el-input
                                    v-model="queryParams.sfvip"
                                    placeholder="请输入是否vip"
                                    clearable
                                    size="mini"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
						<el-form-item label="会员类型" prop="userType" class="el-form-search-item">
						    <el-input
						            v-model="queryParams.userType"
						            placeholder="请输入"
						            clearable
						            size="mini"
						            @keyup.enter.native="handleQuery"
						    />
						</el-form-item>
            <el-form-item class="el-form-search-item">
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
    </el-row>

    <el-table :height="tableHeight" v-loading="loading" :data="buzMemberList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="#" type="index" width="50" align="center">
            <template scope="scope">
          <span>{{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}</span>
            </template>
        </el-table-column>
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="手机号码" align="center" prop="phone" />
      <el-table-column label="高考总分" align="center" prop="grade" />
	  <el-table-column label="区外高校分数" align="center" prop="gxgrade" />
	  <el-table-column label="区内高校分数" align="center" prop="gxgrade" />
      <el-table-column label="首选科目" align="center" prop="sxkm" />
      <el-table-column label="再选科目" align="center" prop="zxkm" />
      <el-table-column label="是否少数民族" align="center" prop="sfssmz" />
      <el-table-column label="是否国家专项计划" align="center" prop="sfgjzxdfzx" />
	  <el-table-column label="是否地方专项计划" align="center" prop="sfdfzx" />
      <el-table-column label="是否vip" align="center" prop="sfvip" />
	  <el-table-column label="会员类型" align="center" prop="userType" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:buzMember:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:buzMember:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改会员信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false" v-dialogDrag>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="手机号码" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号码" />
        </el-form-item>
        
        <el-form-item label="高考总分" prop="grade">
          <el-input v-model="form.grade" placeholder="请输入高考总分" />
        </el-form-item>
		<el-form-item label="区外高校分数" prop="qggrade">
		  <el-input v-model="form.qggrade" placeholder="请输入区外高校分数" />
		</el-form-item>
		<el-form-item label="区内高校分数" prop="grade">
		  <el-input v-model="form.gxgrade" placeholder="请输入区内高校分数" />
		</el-form-item>
        <el-form-item label="首选科目" prop="sxkm">
          <el-input v-model="form.sxkm" placeholder="请输入首选科目" />
        </el-form-item>
        <el-form-item label="再选科目" prop="zxkm">
          <el-input v-model="form.zxkm" placeholder="请输入再选科目" />
        </el-form-item>
        <el-form-item label="是否少数民族" prop="sfssmz">
          <el-input v-model="form.sfssmz" placeholder="请输入是否少数民族" />
        </el-form-item>
        <el-form-item label="是否国家专项计划" prop="sfgjzxdfzx">
          <el-input v-model="form.sfgjzxdfzx" placeholder="请输入是否国家专项计划" />
        </el-form-item>
		<el-form-item label="是否地方专项计划" prop="sfdfzx">
		  <el-input v-model="form.sfgjzxdfzx" placeholder="请输入是否地方专项计划" />
		</el-form-item>
        <el-form-item label="是否vip" prop="sfvip">
          <el-input v-model="form.sfvip" placeholder="请输入是否vip" />
        </el-form-item>
		<el-form-item label="会员类型" prop="userType">
		  <el-input v-model="form.userType" placeholder="请输入" />
		</el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBuzMember, getBuzMember, delBuzMember, addBuzMember, updateBuzMember } from "@/api/system/buzMember";

export default {
  name: "BuzMember",
  data() {
    return {
      // 表格高度
      tableHeight: document.documentElement.clientHeight - 180,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会员信息表格数据
      buzMemberList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: "create_time",
        isAsc: "desc",
        phone: null,
        
        userType: null,
        sxkm: null,
        zxkm: null,
        sfssmz: null,
        sfgjzxdfzx: null,
		sfdfzx: null,
        sfvip: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询会员信息列表 */
    getList() {
      this.loading = true;
      listBuzMember(this.queryParams).then(response => {
        this.buzMemberList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        phone: null,
        memberName: null,
        province: null,
        createTime: null,
        openid: null,
        avatar: null,
        grade: null,
        sxkm: null,
        zxkm: null,
        sfssmz: null,
        sfgjzxdfzx: null,
        sfvip: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加会员信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBuzMember(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改会员信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBuzMember(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBuzMember(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除记录？').then(function() {
        return delBuzMember(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
};
</script>
